//package com.origin.learn.com.origin.learn.commands;
//
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//
///**
// * @Description: 调用本地批处理脚本的工具类
// * @Date: 2019/12/13
// * @Time: 17:19
// * @Created by:   dingtao
// * @Modified by:
// * @Modified at:
// */
//public class CommandUtil {
//
//    public static void mains(String[] args) throws Exception{
//        Runtime.getRuntime().exec("cmd /c dir > %dest%", new String[]{"dest=d:\\dir.txt"}, new File("d:\\software"));
////        int exitVal = proc.waitFor(); // 阻塞当前线程，并等待外部程序中止后获取结果码
////        System.out.println(exitVal == 0 ? "成功" : "失败");
//
//        Runtime.getRuntime().exec("cmd /c dir > %dest%", new String[]{"dest=D:\\log.txt"}, new File("D:\\software"));
////        System.out.println(execWithEcho("ipconfig", "GBK"));
//    }
//
//    /**
//     * 该方法将在本机调用{@code command} 命令，并将命令的输出结果以{@code echoCharset}的编码方式返回
//     *
//     * @param command     待执行命令
//     * @param echoCharset 返回结果的编码方式
//     * @return
//     * @throws IOException
//     */
//    public static String execWithEcho(String command, String echoCharset) throws IOException {
//        Process process = Runtime.getRuntime().exec(command);
//
//        StringBuilder stringBuilder = new StringBuilder();
//        try (InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), echoCharset);
//             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                stringBuilder.append(line+"\n");
//            }
//        }
//        return stringBuilder.toString();
//    }
//
//    public static void exec(String command) throws IOException{
//        Runtime.getRuntime().exec(command);
//    }
//}
